package project.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import project.dao.UserMapper;
import project.model.User;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public Boolean login(String username, String password) {
        User result = userMapper.login(username, password);
        return result!= null;
    }

    @Override
    public int updateUser(User user) {
        return user.getPassword() == null? userMapper.updateUserPhone(user) :
                userMapper.updateUserPassword(user);
    }

    @Override
    public int deleteUser(int uid) {
        return userMapper.deleteUser(uid);
    }

    @Override
    public User selectById(Integer idInt) {
        return userMapper.selectById(idInt);
    }
    @Override
    public User selectByName(String username) {
        return userMapper.selectByName(username);
    }
}
